#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    char str[3];
    int a[11][11],b[11][11];
    int n, m, i, j, d,x ,y, c; 
    while(scanf("%s",str) !=EOF)
    {
        if(strcmp("IN",str)==0)
        {
            d = 1;
            scanf("%d %d",&n,&m);
            for(i = 0;i < n;i++)
            {
                for(j = 0;j < m;j++,d++)
                {
                    a[i][j] = d;
                    b[i][j] = d;
                }
            }
        }
        if(strcmp("SR",str) == 0)
        {
            scanf("%d %d",&x, &y);
            for(i = 0;i < m; i++)
            {
                b[x-1][i] = a[y-1][i];
                b[y-1][i] = a[x-1][i];
            }
        }
        if(strcmp("SC",str) ==0)
        {
            scanf("%d %d",&x,&y);
            for(i = 0;i < n;i++)
            {
                b[i][x-1] = a[i][y-1];
                b[i][y-1] = a[i][x-1];
            }            
        }
        if(strcmp("TR",str) == 0)
        {
            for(i = 0;i < n;i++)
            {
                for(j = 0;j < m;j++)
                {
                    b[j][i] = a[i][j];
                }
            }
            c = n;
            n = m;
            m = c;
            
        }
        if(strcmp("FR",str) == 0)
        {
            for(i = 0;i < n/2;i++)
            {
                for(j = 0;j < m;j++)
                {
                    b[n-i-1][j] = a[i][j];
                    b[i][j] = a[n-i-1][j];
                }
            }
        }
        if(strcmp("FC",str) == 0)
        {
            for(i = 0;i <m/2;i++)
            {
                for(j = 0;j < n;j++)
                {
                    b[j][m-i-1]=a[j][i];
                    b[j][i] = a[j][m-i-1];
                }
            }
        }
        if(strcmp("PR",str) == 0)
        {
            for(i = 0;i<n; i++)
            {
                printf("%d",a[i][0]); 
                for(j = 1;j<m;j++)
                {
                      printf("% d",a[i][j]);
                }
                printf("\n");
            }
            printf("\n"); 
        }
        for(i = 0;i < n;i++)
            {
                for(j = 0;j<m;j++)
                {
                    a[i][j] = b[i][j];
                }
            }
    }    
} 
